struct PixelShaderShadowOutput
{
    half4 Depth : COLOR0;
};

struct VertexOutputShadow
{
	float4 Position		: POSITION0;
	float2 texCoord			: TEXCOORD0;
	float4 Depth : TEXCOORD2;
};

struct VertexInputShadow
{
	float4 position		: POSITION0;
	float2 texCoord		: TEXCOORD0;
};

uniform const float depthBias;
uniform const float ShadowSize;
float CalcShadowTermSoftPCF3X(float fLightDepth,float2 vShadowTexCoord,sampler shadowsampler)
{
	float fShadowTerm = 0.0f;  
	float fWeightAccum = 0.0f;

	fShadowTerm	= 0;

	float depthCheck	= fLightDepth - depthBias;
	float2 f	= frac(vShadowTexCoord * ShadowSize);

	float s	= 1 / ShadowSize;
	fShadowTerm	+= f.x * f.y * ceil(1 - (depthCheck / tex2D(shadowsampler,vShadowTexCoord + float2(s,s)).x));
	fShadowTerm	+= (1 - f.x) * f.y * ceil(1 - (depthCheck / tex2D(shadowsampler,vShadowTexCoord + float2(-s,s)).x));
	fShadowTerm	+= f.x * (1 - f.y) * ceil(1 - (depthCheck / tex2D(shadowsampler,vShadowTexCoord + float2(s,-s)).x));
	fShadowTerm	+= (1 - f.x) * (1 - f.y) * ceil(1 - (depthCheck / tex2D(shadowsampler,vShadowTexCoord + float2(-s,-s)).x));

	fShadowTerm	+= f.x * ceil(1 - (depthCheck / tex2D(shadowsampler,vShadowTexCoord + float2(s,0)).x));
	fShadowTerm	+= f.y * ceil(1 - (depthCheck / tex2D(shadowsampler,vShadowTexCoord + float2(0,s)).x));
	fShadowTerm	+= (1 - f.x) * ceil(1 - (depthCheck / tex2D(shadowsampler,vShadowTexCoord + float2(-s,0)).x));
	fShadowTerm	+= (1 - f.y) * ceil(1 - (depthCheck / tex2D(shadowsampler,vShadowTexCoord + float2(0,-s)).x));

	fShadowTerm	= 0.8 * (fShadowTerm * 2 / 8);

	fShadowTerm	+= 0.2 * ceil(1 - (depthCheck / tex2D(shadowsampler,vShadowTexCoord).x));

	return saturate(fShadowTerm);
}

uniform const float4x4 lightMatrix;
uniform const float4x4 textureScaleBias;

uniform const texture shadowMap;
sampler shadowMapSampler = sampler_state
{
    Texture = <shadowMap>;
    MinFilter = point;
    MagFilter = point;
    MipFilter = point;
    AddressU = Clamp;
    AddressV = Clamp;
    AddressW = Clamp;

};